package hot100;

import java.util.Deque;
import java.util.LinkedList;

public class dailyTemperatures {
    public int[] dailyTemperatures(int[] temperatures) {
        int n = temperatures.length;
        int[] ret = new int[n];
        Deque<Integer> stack = new LinkedList<Integer>();

        for(int i = 0;i < n;i++) {
            while(!stack.isEmpty() && temperatures[i] > temperatures[stack.peek()]) {
                int t = stack.pop();
                ret[t] = i - t;
            }
            stack.push(i);
        }
        return ret;

    }
}
